<?php
/**
 * Created by PhpStorm.
 * User: xeng
 * Date: 2017/12/28
 * Time: 18:45
 */
namespace Home\Controller;
use Org\Net\IpLocation;
use Think\Controller;
use Think\Exception;

class UserController extends Controller {
    public function index(){
        $this->redirect('User/login');
    }
    /*
     * MYSQL 链接分装
     */
    protected function weblog($query_sql){
       if(empty($mysql1_con)){
           $servername = C('DB_HOST');
           $username = C('DB_USER');
           $password = C('DB_PWD');
           $dbname = C('DB_NAME');
            // 创建连接
            $conn = mysqli_connect($servername, $username, $password, $dbname);
            
            // 检测连接
            if (!$conn) {
                die("Connection failed: " .iconv("gbk","utf-8",mysqli_connect_error()));
            }
            $mysql1 = $conn; //dump($mysql1); //链接留存
            $result = mysqli_query($conn, $query_sql);
            if(is_object($result)){ //select true
                if (mysqli_num_rows($result) > 0) {
                    while($row = mysqli_fetch_assoc($result)) {
                        $reset[] = $row;
                    }
                    return $reset;
                } else {
                    return ;
                }
            }elseif ($result===true){ //update delete insert
                return mysqli_affected_rows($conn); //受影响的行数
            }elseif($result === false){
                return  false;
            }
            // 释放内存
            mysqli_free_result($result);
            mysqli_close($conn);
        }
        die;
    }
        /*
    获取客户端IP
    */ 
    public  function getIP() 
    { 
        if (@$_SERVER["HTTP_X_FORWARDED_FOR"]) 
        $ip = $_SERVER["HTTP_X_FORWARDED_FOR"]; 
        else if (@$_SERVER["HTTP_CLIENT_IP"]) 
        $ip = $_SERVER["HTTP_CLIENT_IP"]; 
        else if (@$_SERVER["REMOTE_ADDR"]) 
        $ip = $_SERVER["REMOTE_ADDR"]; 
        else if (@getenv("HTTP_X_FORWARDED_FOR")) 
        $ip = getenv("HTTP_X_FORWARDED_FOR"); 
        else if (@getenv("HTTP_CLIENT_IP")) 
        $ip = getenv("HTTP_CLIENT_IP"); 
        else if (@getenv("REMOTE_ADDR")) 
        $ip = getenv("REMOTE_ADDR"); 
        else 
        $ip = "Unknown";
        return $ip; 
    }

    //H5支付版本接口请求
    private function http_post_data($url, $params) {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
        curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8'));

        ob_start();
        curl_exec($curl);
        curl_close($curl);
        $contents = ob_get_contents();
        ob_end_clean();

        return json_decode($contents, true);
    }
    // H5支付版本接口错误消息
    private function get_err_msg($code) {
        $err_msg = array(
            '1002' => '支付失败',
            '0000' => '验签失败',
            '0001' => '商户不存在',
            '0002' => '商户未启用',
            '0003' => '必传参数为空',
            '0004' => '产生订单失败',
            '0005' => '订单金额有误',
            '0006' => '订单金额超出支付范围',
            '0007' => '支付类型无效',
            '0017' => '系统异常',
            '0019' => '修改订单支付方式失败',
            '0020' => '交易金额格式错误',
            '0040' => '代理不存在',
            '0041' => '中转手机不存在',
            '0042' => '生成收款码失败',
            '0043' => '未找到商户所属中转手机代理',
            '0044' => '无手机在线',
            '0045' => '未找到商户的支付通道'
        );
        return $err_msg[$code];
    }
    //H5支付版本接口
    public function H5pay(){
        $price = $_GET['price'];
        /*if($price < 20){
           // echo $price;//http://www.4stweb.com/User/H5pay/gameid/1010103/nickname/5201314/price/30
            echo '充值金额不能低于最低限制';
            die();
        }*/
        /*if($price < 20){
            echo  '充值金额非法';
            die();
        }*/
        // 请求订单URL
        $order_url  = "http://sh.aiyft.com/basic/gateway/v1/OrderPay";
        $url = $_SERVER['HTTP_HOST'];
        // 参数
        $params_data = array(
            // 商户号(商户在支付平台系统经过注册认证后被分配的唯一商户号)
            'merId' => 'ba9cfe1c13cf4255b45dcb9cce18e95e',
            // 商户订单号(填写真实的订单号)
            'businessOrderId' => "H5P".(string)time(),
            // 支付金额
            'tradeMoney' => $price,
            // 支付方式(1: 微信支付, 2: 支付宝支付)
            'payType' => 2,
            // 异步通知地址
            'asynURL' => "http://".$url.'/User/hfilnotyle'
        );

        $order_res = $this->http_post_data($order_url, json_encode($params_data, true));
        S(array('type'=>'file','prefix'=>'H5PAY','expire'=>60*60*24));
        // 返回数据错误处理
        $code = $order_res['code'];
        if($code !== '1000') {
            exit($this->get_err_msg($code));
        }
        $order_info = $order_res['info'];

        $command = M('','','DB_CONFIG1');
        $add['gameid'] = $_GET['gameid'];
        $add['nickname'] = $_GET['nickname'];
        $add['price'] = $price;
        $add['outoid'] = $params_data['businessOrderId'];
        $add['channel'] = 0;
        $add['orderstatus'] = 0;
        $add['createtime'] =date('Y-m-d H:i:s');

       // echo $params_data['asynURL'];
        $re = $command->table('data_recharge')->add($add);
        if($re){
            S('MYSQL',$params_data);
            S((string)time(),$order_info);
            Header('Location: '.$order_info['pcodeurl'].'');
        }else{
            echo '支付错误。。';
        }
        //$this->assign('data', $order_info);
        //$this->display('h5pay');
    }
    //H5支付版本接口异步通知参数获取2
    private function get_json_request2() {
        // 获取请求参数
        $request = file_get_contents('php://input');
        if ($request == "") {
            return null;
        }
        //获取$request编码
        $encoding = mb_detect_encoding($request, 'auto');
        //convert to unicode
        if ($encoding != 'UTF-8') {
            //将$request的编码设置为UTF-8
            $request = iconv($encoding, 'UTF-8', $request);
        }
        //将json字符串转为数组
        $request = json_decode($request);
        return $request;
    }




    // 平台公钥
    protected static $publicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgBM5z/Bbb2VyE2cPF0E/ZhmsqmRCJ/mse7uGmUAhUYuThoSABRZ0+bNxEKz76TpbTXxJFFJNaG/roAWMZx155mJkrIVansRrQyig6Tcc8IEVjAtu3hTUvt+TeggdJnSCZiM77EWi0vgb/Imt2EFQpl0icIslvemrYBkUcy7A/Qk7lcShf70JRhjl5ndz/jaP1qz/FXHQ3VhfZFO23E1Sy6rVSlOz4PLRyESbA561jZSILwtJssz6f0OiWUqYpfQy/iA/7gZac1HkO39YonhB9h7O8P+q3vutR3/BEfEyfoHJNeauPSFe/HdRII2jRLe0UkOWQpw2FiBnUVN8fhquJwIDAQAB';

    // 商户私钥
    protected static $merPriKey = 'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCAEznP8FtvZXITZw8XQT9mGayqZEIn+ax7u4aZQCFRi5OGhIAFFnT5s3EQrPvpOltNfEkUUk1ob+ugBYxnHXnmYmSshVqexGtDKKDpNxzwgRWMC27eFNS+35N6CB0mdIJmIzvsRaLS+Bv8ia3YQVCmXSJwiyW96atgGRRzLsD9CTuVxKF/vQlGGOXmd3P+No/WrP8VcdDdWF9kU7bcTVLLqtVKU7Pg8tHIRJsDnrWNlIgvC0myzPp/Q6JZSpil9DL+ID/uBlpzUeQ7f1iieEH2Hs7w/6re+61Hf8ER8TJ+gck15q49IV78d1EgjaNEt7RSQ5ZCnDYWIGdRU3x+Gq4nAgMBAAECggEAFfk2dgKa7WXOSJ3p7Od45R+KjEFfSFSBz0jBMxHZpY/4459gB39u2lh7EY1cOwuUFps4PpBQT5bEKlRJXnekLm67Lw5CGfNBI+iYkuqtwGWlOL3Na7TPO2BIgStbNPnQVY29/i+EXAXNZ2qHtQ6fs6tO+VgmRYsNqBMlew2OdtscfoVM8YU/nGWtBa2rpvpol1/adRWDonb0UjghGkHQb1Jxg7M8tO44hMm+95bPFflsiEftyg2jycAn63T8FNy77J40N/ZMVRKf+6cdfqzIhPZeHSvKt8P4iCvq/AiK4zusnnaE9DRAAtlzRdyjZ3GJkARI7Afkg78ZmcUrlsErAQKBgQC7ZWwv/Nh5yrloIAKM/p0rsdWNOg+HMnJtAobPQq7W5n8Skw5XSSGa5S/pjGMX/hF3BKPVEim1KApmga/oxmKcg7sebZtbsYLdN+VIyxp8zJq+O5FhalprNflpjy4deSZz1A9ElMcFSxWQAQLEd/X/ElSCejIekEi7d+qvSQEWhwKBgQCu9kri1IiNn3+ys7nQCKjKvXdSx83qxbSF49bYytJskcaP2X8XYBs40nRSuMNupCxm0w6F+hURQxkjiP1Twjmvw9c5OMds4EAFr+2jhHCj4a+1jq6tMCyuQd+E9Mse8+dnXZSrzdjAcPYmxhzrRlCTPrU51+C+pVyanffXxfnzYQKBgGtb3bFYYATWeYYH4K46KH0h8sBoJQFFi3ycV/NhtpzzjJVtnmevRAtjhiF9BkB2lDbld57YOwDIIb08SzVGgrQ8W/VAwiKz/c8S+M7NXS1mYrjdk5qFvatyTqOFHdxQzhDJyr11pteHfqDzk0xPlaU+MSBXNWOBMcoFF3S4lGD9AoGAaRSxW1SsguqVpn19Du30enear9Qi32tIhdWWVvRRtzVCXWkShLaLAvCbPoeLkOr3Y/ZE1cCiYJC9C3OeOmz/eooTvGFWnRR+PywvfLLxd+v3PQLp9EhnvW0A0vi2+eshQxqYTSs/kC0IGbeI7OF5SUYzT/9REw97870GesiD22ECgYAoyZL9DYjXenYrK4lw+2IYRM9XhRtSnCgKulc6yp/G3eOfhMZ5uBlNEjhxqluSp9/U14FuKwZW3c4U+p2BB6dIl0jRDRARg1rl312D5hsbdhxaNb8zqZ78KE0xkWQ015SAbA0M0RKnu6BQMuS73wrsuYh/pZtfKNMTthO4YfDrLw==';

    /**
     * 校验$value是否非空
     * if not set ,return true;
     * if is null , return true;
     **/
    protected function checkEmpty($value) {
        if (!isset($value))
            return true;
        if ($value === null)
            return true;
        if (trim($value) === "")
            return true;
        return false;
    }
    /**
     * 获取请求的JSON
     */
    public function get_json_request() {
        // 获取请求参数
        $request = file_get_contents('php://input');
        if ($request == "") {
            return null;
        }
        //获取$request编码
        $encoding = mb_detect_encoding($request, 'auto');
        //convert to unicode
        if ($encoding != 'UTF-8') {
            //将$request的编码设置为UTF-8
            $request = iconv($encoding, 'UTF-8', $request);
        }
        //将json字符串转为数组
        $request = json_decode($request);
        return $request;
    }
    /**
     * 验签
     */
    public function verify($data, $sign) {
        if(!$this->checkEmpty(self::$publicKey)){
            $pubKey = "-----BEGIN PUBLIC KEY-----\n".wordwrap(self::$publicKey, 64, "\n", true)."\n-----END PUBLIC KEY-----";
        }

        ($pubKey) or die('平台RSA公钥错误。请检查公钥文件格式是否正确');

        //调用openssl内置方法验签，返回bool值
        return (openssl_verify($data, base64_decode($sign), $pubKey, OPENSSL_ALGO_SHA1) === 1);
    }

    /**
     *  解密
     **/
    public function decrypt($data) {
        if(!$this->checkEmpty(self::$merPriKey)){
            //拼接字符串
            $priKey = "-----BEGIN RSA PRIVATE KEY-----\n" . wordwrap(self::$merPriKey, 64, "\n", true) ."\n-----END RSA PRIVATE KEY-----";
        }

        ($priKey) or die('您使用的商户私钥格式错误，请检查RSA私钥配置');

        $decodes = str_split(base64_decode($data), 256);
        $strnull = "";
        $dcyCont = "";
        foreach ($decodes as $decode) {
            if (!openssl_private_decrypt($decode, $dcyCont, $priKey)) {
                echo "<br/>" . openssl_error_string() . "<br/>";
            }
            $strnull .= $dcyCont;
        }
        return $strnull;
    }


    //H5支付版本接口异步通知
    public function hfilnotyle(){
        S("sdfsd",'通知已进入');
        S(array('type'=>'file','prefix'=>'H5PAY','expire'=>60*60*24));
        // 订单异步通知数据
        $orderAsyncNotified = $this->get_json_request();
        // 无参数或者转换对象失败
        if ($orderAsyncNotified === null) {
            exit('FAILCURE');
        }

        // 解密后的通知内容
        $content = $this->decrypt($orderAsyncNotified->encrypt);

        // 验签失败
        if(!$this->verify($content, $orderAsyncNotified->sign)) {
            exit('FAILCURE');
        }
        // 字符串转换成JSON对象
        $params = json_decode($content);

        $merId = 'ba9cfe1c13cf4255b45dcb9cce18e95e';
        if($params->merId==$merId){
            S('ztkhjsdfui',$params);
            $commands = M('','','DB_CONFIG1');
            $recharg =  $commands->table('data_recharge')->where("outoid='".$params->orderId."'")->find();
            $save['orderstatus'] = 1;
            $save['serialnum'] = $params->payOrderId;
            $update = $commands->table('data_recharge')->where("outoid='".$params->orderId."'")->save($save);
            if(!$update){
                S('sdfdfsssd','订单更新失败');
            }
            $id_int = intval($recharg['gameid']);
            $serverID = C('DATA_HOST');
            $outOid = $_REQUEST["orderid"];
            $command = array(
                'gameid'=>$id_int,
                'price'=>intval($recharg['price']),
                'outoid'=>$params->orderId,
                'orderid'=>intval($recharg['orderid']),
                'channel'=>0
            );
            $command = json_encode($command);
            $time=date("Y-m-d H:i:s",time());
            $repcname ="recharge";
            $add['ServerIPAddr'] =$serverID;
            $add['Command'] =$command;
            $add['RpcName'] =$repcname;
            $add['Time'] =$time;
            $result=  $commands->table('data_command')->add($add);
            if($result){
                exit('SUCCESS');
            }else{
                S('sdfsdj','命令发送失败');
            }
        }else{
            S('sdfd',$params);
        }
        // // 商户号(商户在支付平台系统经过注册认证后被分配的唯一商户号)
        // echo $orderAsyncNotified->merId;
        // // 支付订单号(平台自己的订单流水号)
        // echo $orderAsyncNotified->payOrderId;
        // // 商户订单号
        // echo $orderAsyncNotified->orderId;
        // // 交易金额
        // echo $orderAsyncNotified->money;
        // // 付款时间(平台账单支付完成时间)
        // echo $orderAsyncNotified->payReturnTime;
        // // 支付方式(1: 微信支付, 2: 支付宝支付)
        // echo $orderAsyncNotified->payType;

    }



      public function getcanshu(){
        $web = M('');
        $dd = $web->table('ltq_payment')->find();
        return $dd;
     }
     public function gamepay(){

        $guoqi  = cookie('chongzhi');
        if(!empty($guoqi)){
           echo '请不要重复充值，2分钟之后再充值';
           die();
        }
        $price = $_GET['price'];
        if($price < 20){
            echo  '充值金额非法';
            die();
        }
        C('TOKEN_ON',false);
        error_reporting(0);
        header("Content-type: text/html; charset=utf-8");
        $canshu = $this->getcanshu();
        $pay_memberid = $canshu['mgroupcode']; //"10021";   //商户ID
        $pay_orderid = 'pay'.date("YmdHis");    //订单号
        $pay_amount = $price;    //交易金额
        $pay_applydate = date("Y-m-d H:i:s");  //订单时间
        $pay_notifyurl = "http://gameway.jxuan168.com:1181/User/paynotyle";   //服务端返回地址
        $pay_callbackurl = "http://gameway.jxuan168.com:1181/User/page";  //页面跳转返回地址
        $Md5key = $canshu['mdkey'];//"tx75c0qbhjnjwpcejk9l5fe7i3exyilz";   //密钥
        $tjurl = $canshu['payapi'];//"http://www.best.23qr.cn/Pay_Index.html";   //提交地址
        $pay_bankcode = $canshu['paytype'];   //银行编码912
        //扫码
        $native = array(
            "pay_memberid" => $pay_memberid,
            "pay_orderid" => $pay_orderid,
            "pay_amount" => $pay_amount,
            "pay_applydate" => $pay_applydate,
            "pay_bankcode" => $pay_bankcode,
            "pay_notifyurl" => $pay_notifyurl,
            "pay_callbackurl" => $pay_callbackurl,
        );
        ksort($native);
        $md5str = "";
        foreach ($native as $key => $val) {
            $md5str = $md5str . $key . "=" . $val . "&";
        }
      //  echo($md5str . "key=" . $Md5key);
        $sign = strtoupper(md5($md5str . "key=" . $Md5key));
        $native["pay_md5sign"] = $sign;
        $native['pay_attach'] = "1234|456";
        $native['pay_productname'] ='VIP基础服务';
        //$res = $this->request_post($tjurl, $native);
        //echo $res;
        $this->assign('tjurl', $tjurl);
        $this->assign('native', $native);
        $this->assign('pay_amount', $pay_amount);
        $command = M('','','DB_CONFIG1');
        $add['gameid'] = $_GET['gameid'];
        $add['nickname'] = $_GET['nickname'];
        $add['price'] = $price;
        $add['outoid'] = $pay_orderid;
        $add['channel'] = 0;
        $add['orderstatus'] = 0;
        $add['createtime'] =$pay_applydate;
        $re = $command->table('data_recharge')->add($add);
        if($re){
            cookie('chongzhi',$pay_orderid,60*2);
        }
        
        $this->display();
    }
    public function page(){
        $returnArray = array( // 返回字段
            "memberid" => $_REQUEST["memberid"], // 商户ID
            "orderid" =>  $_REQUEST["orderid"], // 订单号
            "amount" =>  $_REQUEST["amount"], // 交易金额
            "datetime" =>  $_REQUEST["datetime"], // 交易时间
            "transaction_id" =>  $_REQUEST["transaction_id"], // 流水号
            "returncode" => $_REQUEST["returncode"]
        );
        $md5key = "tx75c0qbhjnjwpcejk9l5fe7i3exyilz";
        ksort($returnArray);
        reset($returnArray);
        $md5str = "";
        foreach ($returnArray as $key => $val) {
            $md5str = $md5str . $key . "=" . $val . "&";
        }
        $sign = strtoupper(md5($md5str . "key=" . $md5key));
        if ($sign == $_REQUEST["sign"]) {
            if ($_REQUEST["returncode"] == "00") {
                $str = "交易成功！订单号：".$_REQUEST["orderid"];
                exit($str);
            }
        }else{
	   echo '非正常访问。。。';
	}
    }

    public function paynotyle(){
        S(array('type'=>'file','prefix'=>'mypay','expire'=>60*60*24));
        $returnArray = array( // 返回字段
            "memberid" => $_REQUEST["memberid"], // 商户ID
            "orderid" =>  $_REQUEST["orderid"], // 订单号
            "amount" =>  $_REQUEST["amount"], // 交易金额
            "datetime" =>  $_REQUEST["datetime"], // 交易时间
            "transaction_id" =>  $_REQUEST["transaction_id"], // 支付流水号
            "returncode" => $_REQUEST["returncode"],
        );
        S($_REQUEST["datetime"],json_decode($returnArray, true));
        $md5key = "tx75c0qbhjnjwpcejk9l5fe7i3exyilz";
        ksort($returnArray);
        reset($returnArray);
        $md5str = "";
        foreach ($returnArray as $key => $val) {
            $md5str = $md5str . $key . "=" . $val . "&";
        }
        $sign = strtoupper(md5($md5str . "key=" . $md5key));
        $commands = M('','','DB_CONFIG1');
        $recharg =  $commands->table('data_recharge')->where("outoid='".$_REQUEST["orderid"]."'")->find();
        if ($sign == $_REQUEST["sign"]) {
            if ($_REQUEST["returncode"] == "00") {
                if(!empty($recharg)){
		    $save['orderstatus'] = 1;
                    $commands->table('data_recharge')->where("outoid='".$_REQUEST["orderid"]."'")->save($save);
                    $id_int = intval($recharg['gameid']);
                    $serverID = C('DATA_HOST');
                    $outOid = $_REQUEST["orderid"];
                    $command = array(
                        'user_id'=>$id_int,
                        'price'=>$recharg['price'],
                        'orderid'=>$outOid['orderid'],
                        'channel'=>0
                    );
                    $command = json_encode($command);
                    $time=date("Y-m-d H:i:s",time());
                    $repcname ="recharge";
                    $add['ServerIPAddr'] =$serverID;
                    $add['Command'] =$command;
                    $add['RpcName'] =$repcname;
                    $add['Time'] =$time;
                    $result=  $commands->table('data_command')->add($add);
                    if($result){
                        $str = "交易成功！订单号：".$_REQUEST["orderid"];
                        file_put_contents("success.txt",$str."\n", FILE_APPEND);
                        exit("ok");
                    }
                }
            }
        }
    }    
   //用户登录
    public function login(){
       $this->config= include dirname(dirname(__DIR__)).'/Common/conf/config.php';
        //echo md5('58hao.'.C('MD5_SALT'));
        if(IS_POST){
            //验证用户是否存在
            if($user =D("Admin")->McheckLogin()){//返回用户的记录 或者false
                // 状态的保存
                $session_id=session_id();
                $id=$user['id'];
                $name=$user['name'];
                $blacklist=$user['blacklist'];
                $logtime=date('Y-m-d H:i:s',time());
                $ip=$this->getIP();

                $useraccount = M('','','DB_CONFIG2');
                $lists= $this->weblog("
                    INSERT INTO data_login_logs (operatorid,operator,logtime,ip) VALUES ($id,'$name','$logtime','$ip')
                ");

                $list=$this->weblog("UPDATE ltq_admin  SET session_id='$session_id' WHERE  id=$id");
                $_SESSION['ltq_game_admin_user'] = array("id"=>$user['id'],"name"=>$user['name'],"role"=>$user['role'],"power"=>$user['power'],"session_id"=>$session_id,"blacklist"=>$blacklist);
                session_write_close();
                // 获取 权限及菜单
                $this->success("登录成功",U('Index/index'));
            }else{
                $this->error('登陆失败!!!');
            }
        }else{
            $this->display();
        }
    }

    public function test(){
        S(array('type'=>'file','prefix'=>'zaixiankefu','expire'=>60*60*24));
        S('myname',json_encode($_POST));
        $problem = M('','','DB_CONFIG2');
        if(!empty($_POST) && IS_POST){
            $data['gameid'] = I('post.gameid');
            $data['msg'] = I('post.content');
            $data['time'] = I('post.time');
            $result=$problem->table('game_problem')->add($data);
            if($result){
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }

    }
    //获取公告
    public function getnoticeclie(){
        $useraccount = M('','','DB_CONFIG1');
        $list = $useraccount->table('cfg_notice')->order('sort asc')->select();
        if(!empty($list)){
            echo json_encode($list);
        }else{
            return false;
        }

    }

    public function chongzhi(){
        S(array('type'=>'file','prefix'=>'zhifu','expire'=>60*60*24));
        S('zhifu',json_encode($_GET));
        $problem = M('','','DB_CONFIG1');
        if(!empty($_GET) && IS_GET){
            $commands = M('','','DB_CONFIG1');
            $serverID = C('DATA_HOST');
            $id_int = intval($_GET['gameid']);
            $price = intval($_GET['price']);
            $command=array(
                'gameid'=>$id_int,
                'price'=>$price,
                'outoid'=>date('YmdHis'),
                'orderid'=>0,
                'channel'=>2
            );
            $command = json_encode($command);
            $rpcname="recharge";
            $time=date("Y-m-d H:i:s",time());
            $add['ServerIPAddr'] =$serverID;
            $add['Command'] =$command;
            $add['RpcName'] =$rpcname;
            $add['Time'] =$time;
            $result=  $commands->table('data_command')->add($add);
            if($result){
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }

    }

    public function logout(){
        $_SESSION['ltq_game_admin_user']='';
        $this->redirect('user/login');
    }

    //注册
    public function register(){
        if(!$_SESSION['ltq_game_admin_user']){
            $this->redirect("login");
        }
        $this->display();

    }

    //登录超时
    public function lockscreen(){
        $this->display();
    }



    public function payment(){
        $pay = M('');
        $this->CheckPower('9100');
        if(IS_POST){
            $data['mdkey'] = $_POST['mdkey'];
            $data['merchantcode'] = $_POST['merchantcode'];
            $data['mgroupcode'] = $_POST['mgroupcode'];
            $data['password'] = $_POST['password'];
            $data['payapi'] = $_POST['payapi'];
            $data['username'] = $_POST['username'];
            $data['weburl'] = $_POST['weburl'];
            $data['paytype'] = $_POST['paytype']; //支付类型
            $re['code'] = 0;
            $re['msg'] = '操作失败';
            $resss = $pay->table('ltq_payment')->where('id=1')->save($data);
            if($resss){
                $re['code'] = 1;
                $re['msg'] = '更新成功';
            }
            $this->ajaxReturn($re);
        }

        $data = $pay->table('ltq_payment')->where('id=1')->find();
        $this->assign('data', $data);
        $this->display();
    }

    //权限验证
    function CheckPower($power){
        if($_SESSION["ltq_game_admin_user"]['power']=='all')
            return 1;// $this->nop();//  return 1;
        $power=$power.',';
        if (strpos($_SESSION["ltq_game_admin_user"]['power'], $power)===false) {
            $this->nop();
        }
        return 1;
    }







    public function profile(){
        $this->display();
    }
    public function lists(){
        $this->display();
    }

    public function reset(){
        $this->display();
    }



}
